using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Pub_Module_J_News : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
     /*   if (!IsPostBack)
            BindData();*/
    }
    public string LimitWord(string value)
    {
        //String html = "Whatever your html is";
        //html = Regex.Replace(html, @"</?[^>]*>", ""); 
        value = StripHtml(value, false);

        int length = 400;
        if (value.Length > length)
            return "&nbsp;&nbsp;" + value.Substring(0, length) + "...";
        else
            return "&nbsp;&nbsp;" + value;

    }

    public static string StripHtml(string html, bool allowHarmlessTags)
    {
        if (html == null || html == string.Empty)
            return string.Empty;

        if (allowHarmlessTags)
            return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty);

        return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);
    }


    private void BindData()
    {
        string viewcount = System.Configuration.ConfigurationManager.AppSettings["TopNews"];
        string KindNo = "N";
        if (Request.QueryString["KindNo"] != "" && Request.QueryString["KindNo"] != null)
            KindNo = Request.QueryString["KindNo"];
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("NewsID", "0");
        msg.CreateFirstNode("Title", "");
        msg.CreateFirstNode("KindNo", cls.killSQLInjection(KindNo));
        msg.CreateFirstNode("Status", "");
        msg.CreateFirstNode("ViewCount", viewcount);

        DataTable dt = null;
        dt = cls.Get_NewsByCondition(msg.GetXmlStr).Tables[0];


        if (dt.Rows.Count > 0)
        {
            string HTML = "<div id='lofslidecontent45' class='lof-slidecontent'>";
            HTML += "<div class='preload'><div></div></div>";
            HTML += " <div class='lof-main-outer'>";
            HTML += " <ul class='lof-main-wapper'>";
            //Navigator
            string HTML1 = "";
            HTML1 += " <div class='lof-navigator-outer'>";
            HTML1 += " <ul class='lof-navigator'>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string url = "Common/News/NewsDetail.aspx?NewsID=" + dt.Rows[i]["NewsID"].ToString();
                HTML += "<li>";
                HTML += "<img src='" + dt.Rows[i]["ImgUrl"].ToString() + "'   width='175px' height='189px' />";
                HTML += " <div class='lof-main-item-desc'>";
                HTML += " <a href='" + url + "' style='color:white' class='LofTitile'>" + dt.Rows[i]["Title"].ToString() + " </a>";
                HTML += "</br>";
                HTML += "<div class='LofContent'>" + LimitWord(StripHtml(dt.Rows[i]["Content"].ToString(),true)) + "</div>";           
                HTML += "</div>";
                HTML += "</li>";

                //Navigator
                HTML1 += "<li>";
                HTML1 += "<div>";
                HTML1 += "<img src='" + dt.Rows[i]["ImgUrl"].ToString() + "'  />";
                HTML1 += " <h5><a href='" + url + "' style='color:white' class='LofTitile'>" + dt.Rows[i]["Title"].ToString() + "</a></h5>";
                HTML1 += "</div>";
                HTML1 += "</li>";    


            }
            HTML += "</ul>";
            HTML += "</div>";

            HTML += HTML1;            
            HTML += "</ul>";
            HTML += "</div>";
            HTML += "</div>";
          
            ltrMaster.Text = HTML;
        }
    }
}
